﻿using System;

namespace SuperX.DataCenterService
{
    public class InstanceBase<T> where T : class, new()
    {
        private static readonly object Lock = new object();

        private static T _instance;

        public DateTime CreateTime { get; set; }

        public static T Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (Lock)
                    {
                        if (_instance == null)
                        {
                            _instance = new T();
                        }
                    }
                }

                return _instance;
            }
        }

        public static void ClearInstance()
        {
            _instance = null;
        }

        public InstanceBase()
        {
            CreateTime = DateTime.Now;
        }
    }
}